package com.cq.hd.admin.controller;

import com.cq.hd.admin.annotation.RequiresPermissionsDesc;
import com.cq.hd.common.pagination.Page;
import com.cq.hd.common.response.Result;
import com.cq.hd.common.response.ResultGenerator;
import com.cq.hd.system.api.TbContentApi;
import com.cq.hd.system.api.dto.ContentPageDto;
import com.cq.hd.system.api.dto.ContentSaveDto;
import com.cq.hd.system.api.dto.ContentUpdateDto;
import com.cq.hd.system.api.dto.ContentUpdateStateDto;
import com.cq.hd.system.api.vo.ContentPageVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Api(tags = "学院文章相关接口")
@Slf4j
@RestController
@RequestMapping("/content")
public class TbContentController extends BaseController {

    private TbContentApi contentApi;

    @Autowired
    public void setContentApi(TbContentApi contentApi) {
        this.contentApi = contentApi;
    }

    @ApiOperation(value = "学院文章列表")
    @ApiImplicitParam(name = "contentPageDto", value = "学院文章查询参数", paramType = "query", dataType = "ContentPageDto")
    @ApiResponse(response = ContentPageVo.class, code = 200, message = "接口返回对象参数")
    @RequiresPermissions("content:content:list")
    @RequiresPermissionsDesc(menu = {"火火学院管理", "内容文章"}, button = "查询")
    @GetMapping("/page")
    public Result<Page<ContentPageVo>> pageContent(ContentPageDto contentPageDto) {
        contentPageDto.setOrderType(2);
        return contentApi.pageContent(contentPageDto);
    }

    @ApiOperation(value = "保存学院文章")
    @ApiImplicitParam(name = "contentSaveDto", value = "学院文章保存参数", paramType = "body", dataType = "ContentSaveDto")
    @RequiresPermissions("content:content:save")
    @RequiresPermissionsDesc(menu = {"火火学院管理", "内容文章"}, button = "添加")
    @PostMapping("/save")
    public Result<Long> saveContent(@Validated @RequestBody ContentSaveDto contentSaveDto) {
        return contentApi.saveContent(contentSaveDto);
    }

    @ApiOperation(value = "更新学院文章")
    @ApiImplicitParam(name = "contentUpdateDto", value = "学院文章更新参数", paramType = "body", dataType = "ContentUpdateDto")
    @RequiresPermissions("content:content:update")
    @RequiresPermissionsDesc(menu = {"火火学院管理", "内容文章"}, button = "更新")
    @PostMapping("/update")
    public Result<Boolean> updateContent(@Validated @RequestBody ContentUpdateDto contentUpdateDto) {
        return contentApi.updateContent(contentUpdateDto);
    }

    @ApiOperation(value = "删除学院文章")
    @ApiImplicitParam(name = "id", value = "学院文章删除参数", required = true, paramType = "query", dataType = "Long")
    @RequiresPermissions("content:content:delete")
    @RequiresPermissionsDesc(menu = {"火火学院管理", "内容文章"}, button = "删除")
    @PostMapping("/delete")
    public Result<Boolean> deleteContent(Long id) {
        return contentApi.deleteContent(id);
    }

    @ApiOperation(value = "上下架学院文章")
    @ApiImplicitParam(name = "contentUpdateStateDto", value = "学院文章上下架参数", paramType = "body", dataType = "ContentUpdateStateDto")
    @RequiresPermissions("content:content:updateState")
    @RequiresPermissionsDesc(menu = {"火火学院管理", "内容文章"}, button = "上下架")
    @PostMapping("/updateState")
    public Result<Boolean> updateState(@RequestBody ContentUpdateStateDto contentUpdateStateDto) {
        return contentApi.updateState(contentUpdateStateDto);
    }
}
